# 根据数据文件生成数据列表
import os


def write_paths(dataset_path, mode='train'):
    """将文件相对路径存储在txt格式文件中"""
    with open(os.path.join(dataset_path, (mode + '.txt')), 'w') as f:
        image_A_path = os.path.join(os.path.join(dataset_path, mode), 'A')
        # 获取文件夹下的所有文件名
        image_names = os.listdir(image_A_path)
        image_names.sort()
        for image_name in image_names:
            image_A = os.path.join(image_A_path, image_name)
            image_B = os.path.join(os.path.join(os.path.join(dataset_path, mode), 'B'), image_name)
            image_label = os.path.join(os.path.join(os.path.join(dataset_path, mode), 'label'), image_name)
            # 写入list.txt
            f.write(image_A + ' ' + image_B + ' ' + image_label + '\n')
    print(f'{mode}.txt')


if __name__ == '__main__':
    # data 的文件夹
    dataset_path = '../../data1/ForestCD'
    # 生成文件路径，并保存至txt文件
    write_paths(dataset_path, mode='train')
    write_paths(dataset_path, mode='test')
    write_paths(dataset_path, mode='val')

# python tools/data/split_dataset_list.py <dataset_root> images labels --split 0.6 0.2 0.2 --format jpg png
